#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import g
from flask_restful import Resource
from common.auth import Auth

basic_auth, token_auth, multi_auth = Auth.getInstance()

class SaleOrderListAPI(Resource):
    decorators = [multi_auth.login_required]

    def get(self):
        order_model = g.odoo.model('sale.order')
        order_ids = order_model.search([])
        order_list = order_model.read(order_ids, ['id', 'name', 'user_id', 'partner_id', 'state', 'date_order'])
        return {'list': order_list}

class SaleOrderAPI(Resource):
    decorators = [multi_auth.login_required]

    def get(self, id):
        order_model = g.odoo.model('sale.order')
        order_id = order_model.read(id, ['id', 'name', 'user_id', 'partner_id', 'state', 'date_order'])
        return order_id